<?php

namespace App\Service;

use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Guzzle\ClientFactory;
use Hyperf\Di\Annotation\Inject;

class AliyunService {

    /**
     * @Inject
     * @var ClientFactory
     */
    protected ClientFactory $clientFactory;

    protected string $appCode = '76369e7b3053412c9ebcbdb99f12a1b5';//暂时只用appCode简单认证
    protected string $appKey = '204281862';
    protected string $appSecret = 'KCaa8sbrwdvWARRV4CtJAUtzEn6grJDJ';

    /**
     * 请求实名认证接口
     * @param string $idcard
     * @param string $name
     * @return mixed
     * @throws GuzzleException
     */
    public function check(string $idcard, string $name): mixed {
        $client = $this->clientFactory->create(['verify' => false]);
        $url = "https://smsfzsm.market.alicloudapi.com/eid/check";
        $options = [
            'headers' => [
                'Authorization' => 'APPCODE ' . $this->appCode
            ],
            'form_params'    => [
                'idcard' => $idcard,
                'name'   => $name,
            ]
        ];
        $response = $client->post($url, $options);
        return json_decode($response->getBody()->getContents(), true);
    }

}